﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NetworkSimulator
{
    public class WSP : Routing
    {
        public WSP()
            : base()
        {

        }

        /*******************************************************************
        *  WSP (Widest Shortest Path)
        *  
        *  CODER:  HOANG CHUNG HIEN
        *  DATE:   29/3/2013
        *  VERSION: 1.0
        *  
        *******************************************************************/
        public override Path  getPath(Request req)
        {
            this.Renew();
            this.removeLinks(req.Bandwidth);

            // If has at least one path from req.source to req.dest
            if (BFS(nodes[req.Source], nodes[req.Destination]).Links.Count > 0)
            {
                List<Path> paths = getShortestPaths(nodes[req.Source], nodes[req.Destination]);
                double max_bw = double.MinValue;
                Path result_path = new Path();
                foreach (Path path in paths)
                {
                    if (max_bw < path.ResidualBandwidth)
                    {
                        max_bw = path.ResidualBandwidth;
                        result_path = path;
                    }
                }
                return result_path;
            }

            return new Path();
        }

        
    }
}
